import 'package:flutter/material.dart';
import 'package:multi_clickable_shape_widget/multi_clickable_shape_widget.dart';

class HomePage extends StatefulWidget {
  const HomePage({super.key});

  @override
  State<StatefulWidget> createState() => HomePageState();
}

class HomePageState extends State<HomePage> {
  var controller = MultiClickableShapeController(false);
  @override
  void initState() {
    super.initState();
    controller.setParams =
        '{"lines":[{"line":[{"dx":0.0,"dy":0.0},{"dx":0.0,"dy":62.0},{"dx":300.0,"dy":0.0}],"color":4280391411},{"line":[{"dx":0.0,"dy":62.0},{"dx":300.0,"dy":62.0},{"dx":300.0,"dy":0.0}],"color":4282706920}],"radius":5.0,"width":300.0,"height":62.004483579719356,"bgColor":4292927712}';
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(
        child: Column(
          children: [
            SizedBox(height: 10),
            Expanded(
              child: Center(
                child: MultiClickableShapeWidget(
                  controller: controller,
                  painter: My2Painter(),
                  onShapeTap: (l) {
                    print("点击了${l.length}层");
                  },
                ),
              ),
            ),
            MultiClickableShapeEditWidget(controller: controller),
          ],
        ),
      ),
    );
  }
}

class My2Painter extends CustomPainter {
  @override
  void paint(Canvas canvas, Size size) {
    canvas.drawCircle(
      Offset(size.width / 2, size.height / 2),
      10,
      Paint()..color = Colors.red,
    );
  }

  @override
  bool shouldRepaint(covariant CustomPainter oldDelegate) => true;
}
